package com.stephen.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by stephen on 2021-03-30 21:47 .
 * Description: 重定向,新地址需要加上上下文路径
 */
public class RedirectServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 重定向其实分两步
        // 1. 设置Location
        // resp.setHeader("Location","/s01/image");
        // 2. 设置状态码为302
        // resp.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
        resp.sendRedirect("/s01/image");
    }
}
